//
//  AnalysisViewController.m
//  ForYourBeauty
//
//  Created by Kelly xu on 2019/6/2.
//  Copyright © 2019 changrenTech. All rights reserved.
//

#import "AnalysisViewController.h"
#import "ReportDetailViewController.h"
#import "EmojiManagerViewController.h"
#import "ImagePickerManager.h"
#import "UploadViewModel.h"
#import "ReportViewModel.h"
#import "EmojiManagerViewController.h"
@interface AnalysisViewController ()
@property(nonatomic,weak)IBOutlet UIImageView *listBg;
@property(nonatomic,weak)IBOutlet UIButton *fenxiBtn;
@property(nonatomic,weak)IBOutlet UILabel *beforeStatusLab;
@property(nonatomic,weak)IBOutlet UILabel *afterStatusLab;
@property(nonatomic,strong)UploadViewModel *uploadViewModel;
@property(nonatomic,strong)ReportViewModel *reportViewModel;
@property(nonatomic,strong)NSString *beforeUploadImg;
@property(nonatomic,strong)NSString *afterUploadImg;
@property(nonatomic,strong)NSString *beforeUploadTime;
@property(nonatomic,strong)NSString *afterUploadTime;
@end

@implementation AnalysisViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"分析";
     [self.listBg setImage:[[UIImage imageNamed:@"cornerBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"cornerBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"cornerBg"].size.height/2]];
    self.fenxiBtn.layer.cornerRadius = 20;
    self.beforeStatusLab.hidden = YES;
    self.afterStatusLab.hidden = YES;
}
-(IBAction)selectBeforePhoto:(id)sender{
    EmojiManagerViewController *coureImgVC = [[EmojiManagerViewController alloc]init];
    kWeakSelf;
    coureImgVC.selectBlock = ^(NSString * _Nonnull imgUrl, NSString * _Nonnull time) {
        kStrongSelf;
        strongSelf.beforeUploadImg = imgUrl;
        strongSelf.beforeUploadTime = time;
        strongSelf.beforeStatusLab.hidden = NO;
    };
    [self.rt_navigationController pushViewController:coureImgVC animated:YES complete:nil];
}
-(IBAction)selectAfterPhoto:(id)sender{
    EmojiManagerViewController *coureImgVC = [[EmojiManagerViewController alloc]init];
    kWeakSelf;
    coureImgVC.selectBlock = ^(NSString * _Nonnull imgUrl, NSString * _Nonnull time) {
        kStrongSelf;
        strongSelf.afterUploadImg = imgUrl;
        strongSelf.afterUploadTime = time;
        strongSelf.afterStatusLab.hidden = NO;
    };
    [self.rt_navigationController pushViewController:coureImgVC animated:YES complete:nil];
}
-(IBAction)uploadReport:(id)sender{
    if (EC_ISNullStr(self.beforeUploadImg)) {
        Toast(@"请上传使用前照片");
        return;
    }
    if (EC_ISNullStr(self.beforeUploadImg)) {
        Toast(@"请上传使用后照片");
        return;
    }
    kWeakSelf;
    [self.reportViewModel addReport:self.beforeUploadImg beforeTime:self.beforeUploadTime afterImg:self.afterUploadImg afterTime:self.afterUploadTime addTime:[self currentTime] cmp:^{
        kStrongSelf;
        [strongSelf.rt_navigationController popViewControllerAnimated:YES complete:nil];
    }];
}
-(NSString*)currentTime{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    //设置时区,这个对于时间的处理有时很重要
    
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    
    [formatter setTimeZone:timeZone];
    
    NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
    
    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];
    
    return timeSp;
}
#pragma mark - instance
-(UploadViewModel*)uploadViewModel{
    if (!_uploadViewModel) {
        _uploadViewModel = [[UploadViewModel alloc]init];
    }
    return _uploadViewModel;
}
-(ReportViewModel*)reportViewModel{
    if (!_reportViewModel) {
        _reportViewModel = [[ReportViewModel alloc]init];
    }
    return _reportViewModel;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
